home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 17.0 KB | 629 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: MovieFra.cpp
- // Release Version: $ 1.0d11 $
- //
- // Copyright: © 1993, 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef MOVIEFRA_H
- #include "MovieFra.h"
- #endif
-
- #ifndef MOVIEPAR_H
- #include "MoviePar.h"
- #endif
-
- #ifndef CMOVIE_H
- #include "CMovie.h"
- #endif
-
- #ifndef MOVIESEL_H
- #include "MovieSel.h"
- #endif
-
- // ----- Framework Includes -----
-
- #ifndef FWITERS_H
- #include "FWIters.h"
- #endif
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- // ----- OS Layer Includes -----
-
- #ifndef FWGRAPHX_H
- #include "FWGraphx.h"
- #endif
-
- #ifndef FWMENU_H
- #include "FWMenu.h"
- #endif
-
- #ifndef FWEVENT_H
- #include "FWEvent.h"
- #endif
-
- #ifndef FWRESOUR_H
- #include "FWResour.h"
- #endif
-
- #ifndef FWSTRING_H
- #include "FWString.h"
- #endif
-
- #ifndef FWWINDOW_H
- #include "FWWindow.h"
- #endif
-
- #ifndef FWCFMRES_H
- #include "FWCFMRes.h"
- #endif
-
- #ifndef FWODGEOM_H
- #include "FWODGeom.h"
- #endif
-
- #ifndef FWBARRAY_H
- #include "FWBArray.h"
- #endif
-
- #ifndef FWMEMMGR_H
- #include "FWMemMgr.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_ODFacet_xh
- #include <Facet.xh>
- #endif
-
- #ifndef SOM_ODShape_xh
- #include <Shape.xh>
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef SOM_ODArbitrator_xh
- #include <Arbitrat.xh>
- #endif
-
- #ifndef SOM_ODDispatcher_xh
- #include <Disptch.xh>
- #endif
-
- #ifndef SOM_ODDragAndDrop_xh
- #include <DragDrp.xh>
- #endif
-
- #ifndef SOM_ODDragItemIterator_xh
- #include <DgItmIt.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include <StdProps.xh>
- #endif
-
- #ifndef SOM_ODTranslation_xh
- #include <Translt.xh>
- #endif
-
- // ----- Macintosh Includes -----
-
- #if defined(FW_BUILD_MAC) && !defined(__DRAG__)
- #include <Drag.h>
- #endif
-
- //========================================================================================
- // Runtime Information
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment odfmovie
- #endif
-
- //========================================================================================
- // CLASS CMovieFrame
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CMovieFrame::CMovieFrame
- //----------------------------------------------------------------------------------------
-
- CMovieFrame::CMovieFrame(Environment* ev, ODFrame* odFrame, FW_CPresentation* presentation,
- FW_CPart* part, CMovie* theMovie) :
- FW_CFrame(ev, odFrame, presentation, part),
- fMovie(NULL)
- {
- // Make a copy of the movie
- if (theMovie)
- {
- fMovie = FW_NEW(CMovie, ());
- *fMovie = *theMovie;
- }
-
- this->SetDroppable(ev, TRUE);
- }
-
- //----------------------------------------------------------------------------------------
- // CMovieFrame::~CMovieFrame
- //----------------------------------------------------------------------------------------
-
- CMovieFrame::~CMovieFrame()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CMovieFrame::Draw
- //----------------------------------------------------------------------------------------
-
- void CMovieFrame::Draw(Environment* ev, ODFacet* odFacet, ODShape* invalidShape)
- {
- if (fMovie)
- {
- FW_CPlatformGraphicContext pgc(ev, odFacet);
-
- fMovie->Draw(odFacet->GetWindow(ev)->GetPlatformWindow(ev));
- }
- else
- {
- FW_CFacetContext fc(ev, odFacet, invalidShape);
-
- FW_CPictureShape::RenderPicture(fc, this->GetMoviePart(ev)->GetDefaultPicture(ev), GetBounds(ev));
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CMovieFrame::FacetAdded
- //----------------------------------------------------------------------------------------
-
- void CMovieFrame::FacetAdded(Environment* ev, ODFacet* facet)
- {
- FW_CFrame::FacetAdded(ev, facet);
-
- if (!fMovie && this->GetMoviePart(ev)->GetInternalizedMovie(ev))
- {
- fMovie = FW_NEW(CMovie, ());
- *fMovie = *(this->GetMoviePart(ev)->GetInternalizedMovie(ev));
- }
-
- if (fMovie)
- {
- FW_CRect movieBox;
- FW_CPlatformGraphicContext pgc(ev, facet);
- FW_CAcquiredODWindow aqWindow(this->AcquireODWindow(ev));
-
- fMovie->SetGraphicsWorld(aqWindow->GetPlatformWindow(ev));
- fMovie->SetLooping(this->GetMoviePart(ev)->IsLooping(ev));
- fMovie->EnableKeys(TRUE);
- fMovie->EnableEditing(TRUE);
- fMovie->EnableDragging(FALSE); // We take care of dragging ourselves so don't let the toolbox do it
- fMovie->MakeControllerVisible(this->GetMoviePart(ev)->IsControllerShown(ev) || this->IsRoot(ev));
-
- fMovie->GetBoundingBox(movieBox);
- movieBox.Offset(-movieBox.left, -movieBox.top);
- this->AdjustFrameSize(ev, movieBox);
-
- if (this->IsRoot(ev))
- this->GetWindow(ev)->SetWindowSize(ev, movieBox.BotRight());
-
- fMovie->Activate(aqWindow->GetPlatformWindow(ev), this->HasSelectionFocus(ev));
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CMovieFrame::FrameShapeChanged
- //----------------------------------------------------------------------------------------
- void CMovieFrame::FrameShapeChanged(Environment* ev)
- {
- FW_CFrame::FrameShapeChanged(ev);
-
- FW_CRect boundingBox = GetBounds(ev);
-
- FW_CFrameFacetIterator iter(ev, this);
- for (ODFacet* facet = iter.First(ev); iter.IsNotComplete(ev); facet = iter.Next(ev))
- {
- if (fMovie)
- {
- FW_CPlatformGraphicContext pgc(ev, facet);
- fMovie->SetBoundingBox(boundingBox);
- }
- }
-
- this->Invalidate(ev); // Invalidate Frame shape
- this->GetODFrame(ev)->InvalidateActiveBorder(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CMovieFrame::GeometryChanged
- //----------------------------------------------------------------------------------------
-
- void CMovieFrame::GeometryChanged(Environment *ev,
- ODFacet* odFacet,
- FW_Boolean clipShapeChanged,
- FW_Boolean externalTransformChanged)
- {
- if (fMovie)
- {
- if (clipShapeChanged)
- {
- FW_CPlatformGraphicContext pgc(ev, odFacet);
-
- FW_CAcquiredODShape aqODShape(odFacet->AcquireClipShape(ev, NULL));
- ODRgnHandle clipRegion = ::FW_CopyRegion(aqODShape->GetQDRegion(ev));
-
- fMovie->SetClipShape(clipRegion);
- ::FW_DisposeRegion(clipRegion);
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CMovieFrame::FocusStateChanged
- //----------------------------------------------------------------------------------------
-
- void CMovieFrame::FocusStateChanged(Environment* ev, ODTypeToken focus, FW_Boolean newState, ODFrame* newOwner)
- {
- FW_CFrame::FocusStateChanged(ev, focus, newState, newOwner);
-
- if ((focus == FW_CPart::gSelectionFocusToken) && fMovie)
- {
- ODFacet* facet = this->GetActiveFacet(ev);
- if (facet)
- {
- FW_CPlatformGraphicContext pgc(ev, facet);
-
- fMovie->Activate(facet->GetWindow(ev)->GetPlatformWindow(ev), newState);
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CMovieFrame::DoAdjustMenus
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CMovieFrame::DoAdjustMenus(Environment* ev, FW_CMenuBar* menuBar, FW_Boolean hasMenuFocus, FW_Boolean isRoot)
- {
- ODTypeToken viewType = GetViewType(ev);
- if (hasMenuFocus && (viewType == FW_CPart::gViewAsFrameToken))
- {
- menuBar->EnableCommand(ev, cShowMovieController, fMovie && !this->IsRoot(ev));
- menuBar->EnableAndToggleCommand(ev, cStartStopMovie, fMovie != NULL, fMovie && fMovie->IsPlaying());
-
- menuBar->EnableAndCheckCommand(ev, cSetMovieLooping, TRUE, this->GetMoviePart(ev)->IsLooping(ev));
-
- menuBar->EnableCommand(ev, cChooseMovie, TRUE);
- }
-
- return FALSE;
- }
-
- //------------------------------------------------------------------------------
- // CMovieFrame::DoMenu
- //------------------------------------------------------------------------------
-
- FW_Boolean CMovieFrame::DoMenu(Environment* ev, const FW_CMenuEvent& theMenuEvent)
- {
- FW_Boolean menuHandled = TRUE;
-
- switch (theMenuEvent.GetCommandID(ev))
- {
- case cStartStopMovie:
- {
- FW_CPlatformGraphicContext pgc(ev, this->GetActiveFacet(ev));
-
- if (!fMovie->IsPlaying())
- fMovie->Start();
- else
- fMovie->Stop();
- }
-
- break;
-
- default:
- menuHandled = FALSE;
- }
-
- return menuHandled;
- }
-
- //---------------------------------------------------------------------------------------
- // CMovieFrame::DoMouseDown
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CMovieFrame::DoMouseDown(Environment* ev, const FW_CMouseEvent& theMouseEvent)
- {
- FW_Boolean eventHandled = FALSE;
-
- if (fMovie)
- {
- FW_CPlatformGraphicContext pgc(ev, theMouseEvent.GetFacet(ev));
-
- eventHandled = fMovie->DoMouseDown(ev, theMouseEvent);
-
- if (!fMovie->IsSelectionEmpty())
- this->Drag(ev, theMouseEvent);
- }
-
- return eventHandled;
- }
-
- //----------------------------------------------------------------------------------------
- // CMovieFrame::DoVirtualKeyDown
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CMovieFrame::DoVirtualKeyDown(Environment* ev, const FW_CVirtualKeyEvent& theVirtualKeyEvent)
- {
- if (fMovie)
- {
- FW_CPlatformGraphicContext pgc(ev, this->GetActiveFacet(ev));
-
- return fMovie->DoVirtualKeyDown(ev, theVirtualKeyEvent);
- }
- else
- return FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // CMovieFrame::CanAcceptDrop
- //----------------------------------------------------------------------------------------
-
- ODDragResult CMovieFrame::CanAcceptDrop(Environment *ev, ODDragItemIterator* dragInfo)
- {
- ODDragResult result = FW_CFrame::CanAcceptDrop(ev, dragInfo);
-
- if (!result)
- {
- ODStorageUnit *dragSU;
- HFSFlavor *valueData;
- long valueSize;
-
- ODTranslation *translate = this->GetPart(ev)->GetSession(ev)->GetTranslation(ev);
- ODType typeHFS = translate->GetISOTypeFromPlatformType(ev, 'hfs ', kODPlatformDataType);
- ODType typePICT = translate->GetISOTypeFromPlatformType(ev, 'PICT', kODPlatformDataType);
-
- dragSU = dragInfo->First(ev);
- while (dragSU != NULL && !result)
- {
- if (fMovie && (dragSU->Exists(ev, kODPropContents, typePICT, 0)))
- {
- result = TRUE;
- }
- else if (dragSU->Exists(ev, kODPropContents, typeHFS, 0))
- {
- dragSU->Focus(ev, kODPropContents, kODPosUndefined, typeHFS, 0, kODPosUndefined);
- valueSize = dragSU->GetSize(ev);
- if (valueSize)
- {
- FW_CByteArray byteArray;
- valueSize = dragSU->GetValue(ev, valueSize, byteArray);
- valueData = (HFSFlavor*) FW_CMemoryManager::AllocateBlock(valueSize);
- byteArray.CopyBuffer(valueData, valueSize);
-
- result = valueData->fileType == 'MooV';
-
- FW_CMemoryManager::FreeBlock(valueData);
- }
- }
-
- dragSU = dragInfo->Next(ev);
- }
- }
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // CMovieFrame::AdjustFrameSize
- //----------------------------------------------------------------------------------------
-
- void CMovieFrame::AdjustFrameSize(Environment* ev, const FW_CRect& movieBox)
- {
- FW_CRect frameRect = GetBounds(ev);
- frameRect.Place(FW_kZeroPoint);
-
- if (frameRect != movieBox)
- {
- FW_CAcquiredODShape aqTempShape(::FW_NewODShape(ev, movieBox));
- if (!this->RequestFrameShape(ev, aqTempShape))
- {
- fMovie->SetBoundingBox(frameRect);
- Invalidate(ev);
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CMovieFrame::AdoptNewMovie
- //----------------------------------------------------------------------------------------
-
- void CMovieFrame::AdoptNewMovie(Environment* ev, CMovie* newMovie)
- {
- if (fMovie)
- delete fMovie;
-
- fMovie = newMovie;
- this->GetPart(ev)->Changed(ev); // document has changed
-
- FW_CPlatformGraphicContext pgc(ev, this->GetActiveFacet(ev));
- FW_CAcquiredODWindow aqWindow(this->AcquireODWindow(ev));
-
- fMovie->SetGraphicsWorld(aqWindow->GetPlatformWindow(ev));
- fMovie->SetLooping(this->GetMoviePart(ev)->IsLooping(ev));
- fMovie->EnableKeys(TRUE);
- fMovie->EnableEditing(TRUE);
- fMovie->EnableDragging(FALSE); // We take care of dragging ourselves so don't let the toolbox do it
- fMovie->MakeControllerVisible(this->GetMoviePart(ev)->IsControllerShown(ev) || this->IsRoot(ev));
-
- FW_CRect movieBox;
- fMovie->GetBoundingBox(movieBox);
- movieBox.Place(FW_kZeroPoint);
-
- if (!this->IsRoot(ev))
- this->AdjustFrameSize(ev, movieBox);
- else
- this->GetWindow(ev)->SetWindowSize(ev, movieBox.BotRight());
-
- fMovie->Activate(aqWindow->GetPlatformWindow(ev), this->HasSelectionFocus(ev));
- }
-
- //----------------------------------------------------------------------------------------
- // CMovieFrame::UpdateMovie
- //----------------------------------------------------------------------------------------
-
- void CMovieFrame::UpdateMovie(Environment* ev)
- {
- ODTypeToken viewType = GetViewType(ev);
-
- if (fMovie && (viewType == FW_CPart::gViewAsFrameToken))
- {
- FW_CFrameFacetIterator iter(ev, this);
- for (ODFacet* facet = iter.First(ev); iter.IsNotComplete(ev); facet = iter.Next(ev))
- {
- FW_CPlatformGraphicContext pgc(ev, facet);
- fMovie->Idle();
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CMovieFrame::ToggleLooping
- //----------------------------------------------------------------------------------------
-
- void CMovieFrame::ToggleLooping(Environment* ev, FW_Boolean looping)
- {
- if (fMovie)
- fMovie->SetLooping(looping);
- }
-
- //----------------------------------------------------------------------------------------
- // CMovieFrame::ToggleController
- //----------------------------------------------------------------------------------------
-
- void CMovieFrame::ToggleController(Environment* ev, FW_Boolean showController)
- {
- if (fMovie)
- {
- FW_CFrameFacetIterator iter(ev, this);
- for (ODFacet* facet = iter.First(ev); iter.IsNotComplete(ev); facet = iter.Next(ev))
- {
- FW_CRect movieBox;
-
- fMovie->MakeControllerVisible(showController);
- fMovie->GetBoundingBox(movieBox);
- this->AdjustFrameSize(ev, movieBox);
- this->GeometryChanged(ev, facet, TRUE, FALSE);
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CMovieFrame::CloseSelection
- //----------------------------------------------------------------------------------------
-
- void CMovieFrame::CloseSelection(Environment* ev)
- {
- if (fMovie)
- {
- FW_CFrameFacetIterator iter(ev, this);
- for (ODFacet* facet = iter.First(ev); iter.IsNotComplete(ev); facet = iter.Next(ev))
- {
- FW_CPlatformGraphicContext pgc(ev, facet);
-
- fMovie->CloseSelection();
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CMovieFrame::ClearSelection
- //----------------------------------------------------------------------------------------
-
- void CMovieFrame::ClearSelection(Environment* ev)
- {
- if (fMovie)
- {
- FW_CFrameFacetIterator iter(ev, this);
- for (ODFacet* facet = iter.First(ev); iter.IsNotComplete(ev); facet = iter.Next(ev))
- {
- FW_CPlatformGraphicContext pgc(ev, facet);
-
- fMovie->ClearCurrentSelection();
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CMovieFrame::SelectAll
- //----------------------------------------------------------------------------------------
-
- void CMovieFrame::SelectAll(Environment* ev)
- {
- if (fMovie)
- {
- FW_CFrameFacetIterator iter(ev, this);
- for (ODFacet* facet = iter.First(ev); iter.IsNotComplete(ev); facet = iter.Next(ev))
- {
- FW_CPlatformGraphicContext pgc(ev, facet);
-
- fMovie->SelectAll();
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CMovieFrame::IsSelectionEmpty
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CMovieFrame::IsSelectionEmpty(Environment* ev)
- {
- FW_Boolean empty = TRUE;
-
- if (fMovie)
- empty = fMovie->IsSelectionEmpty();
-
- return empty;
- }
-
- //----------------------------------------------------------------------------------------
- // CMovieFrame::PasteMovieToSelection
- //----------------------------------------------------------------------------------------
-
- void CMovieFrame::PasteMovieToSelection(Environment* ev, CMovie* newMovie)
- {
- if (fMovie)
- {
- FW_CFrameFacetIterator iter(ev, this);
- for (ODFacet* facet = iter.First(ev); iter.IsNotComplete(ev); facet = iter.Next(ev))
- {
- FW_CPlatformGraphicContext pgc(ev, facet);
-
- fMovie->PasteMovieToCurrentSelection(newMovie);
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CMovieFrame::PasteHandleToSelection
- //----------------------------------------------------------------------------------------
-
- void CMovieFrame::PasteHandleToSelection(Environment* ev, FW_PlatformHandle newHandle, OSType handleType)
- {
- if (fMovie)
- {
- FW_CFrameFacetIterator iter(ev, this);
- for (ODFacet* facet = iter.First(ev); iter.IsNotComplete(ev); facet = iter.Next(ev))
- {
- FW_CPlatformGraphicContext pgc(ev, facet);
-
- fMovie->PasteHandleToCurrentSelection(newHandle, handleType);
- }
- }
- }
-
-